package com.example.pool;

import javafx.concurrent.Worker;

import java.util.concurrent.*;

/**
 * @author: dangwen
 * @createDate: 2021/3/15
 */
public class ThreadPoolDemo {
    private static int largestPoolSize;

    public static void main(String[] args) {

//        Executor executor;
//        //                              (int corePoolSize,
//        //                              int maximumPoolSize,
//        //                              long keepAliveTime,
//        //                              TimeUnit unit,
//        //                              BlockingQueue<Runnable> workQueue,
//        //                              ThreadFactory threadFactory,
//        //                              RejectedExecutionHandler handler)
        ExecutorService executorService = new ThreadPoolExecutor(1,1,60,TimeUnit.MILLISECONDS,new ArrayBlockingQueue<>(10)){
            @Override
            protected void beforeExecute(Thread t, Runnable r) {
                System.out.println("1");
            }

            @Override
            protected void afterExecute(Runnable r, Throwable t) {
                System.out.println("2");
            }

            @Override
            protected void terminated() {
                System.out.println("3");
            }
        };


        ExecutorService executorService1 = Executors.newFixedThreadPool(10,Executors.defaultThreadFactory());
        executorService1.execute(new Runnable() {
            @Override
            public void run() {

            }
        });
//
//        Callable c;
//        Future f;
//        Worker w;

        System.out.println(largestPoolSize);
        System.out.println(-1 | 1);
        System.out.println(-1 | 0);
        System.out.println(-1 | 2);
        System.out.println(-1 | 3);
        System.out.println(-1 | 4);
        System.out.println(-1 | 5);
        ArrayBlockingQueue a;
        Executor executor;
        CompletionService completionService = new ExecutorCompletionService<>(Executors.newSingleThreadExecutor());
        Future submit = completionService.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println("2222");
            }
        }, "1");
    }

    ThreadFactory threadFactory = Executors.defaultThreadFactory();
    ExecutorService executorService = new ThreadPoolExecutor(5,10,600,
            TimeUnit.SECONDS,new ArrayBlockingQueue<>(100), threadFactory, new ThreadPoolExecutor.CallerRunsPolicy());

}
